﻿#region Copyright Notice
// This file is part of GestionPedago.
// <description>
// Copyright (C) 2012 ENI Ecole Informatique
// 
// GestionPedago is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// <program> is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace GestionPedago.Converters {

    /// <summary>
    /// Classe IconFileConverter
    /// </summary>
    public class IconFileConverter : IValueConverter {

        #region IValueConverter Membres

        /// <summary>
        /// Renvoi l'icon system lié au type du fichier passé en paramètre
        /// </summary>
        /// <param name="value">chemin vers le fichier</param>
        /// <returns>BitmapSource</returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {

            using(System.Drawing.Icon sysicon = System.Drawing.Icon.ExtractAssociatedIcon(value as string))
            {
                return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
                            sysicon.Handle,
                            System.Windows.Int32Rect.Empty,
                            System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) {
            throw new NotImplementedException();
        }

        #endregion
    }
}
